# $Id: gnu.sh.in 586 2008-08-27 03:24:45Z enki $
#
# class/cache.sh: Gnu.org mining functions
#
# -------------------------------------------------------------------------
test $lib_class_cache_sh || {

# directory setup
# -------------------------------------------------------------------------
: ${prefix:="@prefix@"}
: ${exec_prefix:="@prefix@"}
: ${libdir:="${exec_prefix}/lib"}
: ${shlibdir:="${libdir}/sh"}
: ${localstatedir:="/var"}

# load dependencies
# -------------------------------------------------------------------------
#. $shlibdir/std/var.sh
#. $shlibdir/shell/trap.sh


# cache <name>
#
# constructs a cache instance and if it succeeds
# -------------------------------------------------------------------------
cache()
{
  if mkdir -p "$CACHE_root/$1"; then
    echo "$CACHE_root/$1"
    return 0
  fi
  return 1
}

# cache_put <key> <string>
# -------------------------------------------------------------------------
cache_put()
{
  echo "$2" >$CACHE_root/$1
}

# cache_get <key> [command]
# -------------------------------------------------------------------------
cache_get()
{
  if [ -r "$CACHE_root/$1" ]; then
    cat "$CACHE_root/$1"
    return 0
  elif [ "$#" -gt 1 ]; then
    cache_put "$1" "$(shift && "$@")" &&
    cat "$CACHE_root/$1"
  fi
  return 1
}

# ---[ EOF ]---------------------------------------------------------------
lib_class_cache_sh=:;}
